﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace ProjetoComperio.Test.FakeData
{
    public class FakeObjectSet<TEntity> : IDbSet<TEntity>, IEnumerable where TEntity : class
    {
        private IList<TEntity> _entities;
        IQueryable _query;

        public FakeObjectSet(IEnumerable<TEntity> testData)
            : base()
        {
            _entities = new List<TEntity>(testData);
            _query = _entities.AsQueryable();

        }

        public void Add(TEntity entity)
        {
            _entities.Add(entity);
        }
        public void Delete(TEntity entity)
        {
            _entities.Remove(entity);
        }
        public void Detach(TEntity entity)
        {
            _entities.Remove(entity);
        }
        public void Attach(TEntity entity)
        {
            _entities.Add(entity);
        }


        #region IEnumerable<TEntity> Members

        public IEnumerator<TEntity> GetEnumerator()
        {
            return _entities.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _entities.GetEnumerator();
        }

        #endregion

        #region IQueryable Members

        public Type ElementType
        {
            get { return _query.ElementType; }
        }

        public System.Linq.Expressions.Expression Expression
        {
            get { return _query.Expression; }
        }

        public IQueryProvider Provider
        {
            get { return _query.Provider; }
        }

        #endregion

        #region IDbSet<TEntity> Members


        public TEntity Find(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        public void Remove(TEntity entity)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
